Skip to content

[C++] Bound var data against the remaining buffer so a uint64 length cannot wrap the position - #1175

Open
slachiewicz wants to merge 1 commit into
aeron-io:masterfrom
slachiewicz:cpp-var-data-uint64-length-wrap
Open

slachiewicz wants to merge 1 commit into
aeron-io:masterfrom
slachiewicz:cpp-var-data-uint64-length-wrap

Conversation

@slachiewicz

Copy link
Copy Markdown
Contributor

With a uint64 var data length, the position + length passed to sbePosition() can wrap, pass the bounds check and move the position backwards, so get(dst, len) copies past the buffer and skip() and () return as if the data were present.

get(), skip() and () now compare the length with bufferLength - position, which cannot wrap. getAsString() and getAsStringView() get the same check in #1160.

Part of #969.

Verified: VarDataUint64LengthTest fails on master (heap-buffer-overflow in getPayload() under ASan) and passes here; sbe-tool checkstyle and test, cppbuild and cppbuild --debug-build --sanitise-build pass.

…cannot wrap the position.

Compare dataLength with m_bufferLength - pos rather than checking
pos + dataLength, which wraps for a uint64 length and lets the position
move backwards. Do not go back to the addition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant